package com.ccs.blockchain.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.Consts;
import org.apache.http.entity.StringEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ccs.blockchain.eneity.ParamHeader;
import com.ccs.blockchain.eneity.ParamObj;
import com.ccs.blockchain.eneity.account.AccountParam;

@RestController
@RequestMapping("baidu/feed/account")
public class AccountController extends BaiduFeedController {
	
	@RequestMapping("/getAccountFeed")
    public String getAccountFeed(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    	ParamObj requestParam = JSONObject.parseObject(httpServletRequest.getParameter("param"), ParamObj.class);
    	if (requestParam == null) {
    		return null;
    	}
    	return service(requestParam, "/v1/feed/cloud/AccountFeedService/getAccountFeed");
    }

	@Override
	protected StringEntity genHttpEntity(ParamObj paramObj) {
		StringEntity strEntity = new StringEntity(JSON.toJSONString(genAccountParam(paramObj)), Consts.UTF_8);
		return strEntity;
	}

	private AccountParam genAccountParam(ParamObj paramObj) {
		ParamHeader head = new ParamHeader();
		head.setOpUsername(paramObj.getOpUsername());
		head.setOpPassword(paramObj.getOpPassword());
		head.setTgSubname(paramObj.getTgSubname());
		head.setBceUser(paramObj.getBceUser());
		
		AccountParam param = new AccountParam();
		param.setHeader(head);
		param.setBody(paramObj.getAccountBody());
		
		return param;
	}
}
